package xyz.yeidi.service.impl;

import xyz.yeidi.dao.api.FoodDao;
import xyz.yeidi.dao.impl.FoodDaoImpl;
import xyz.yeidi.pojo.Food;
import xyz.yeidi.service.api.FoodService;
import xyz.yeidi.utils.ConnUtils;

import java.util.List;

/**
 * @Author JIP
 * @Date 2021-08-03 15:57
 * @Version 1.0
 * @Describe :
 */
public class FoodServiceImpl implements FoodService {
    private FoodDao foodDao = new FoodDaoImpl();
    @Override
    public List<Food> getFoodsByBusiness(Integer businessId){
        List<Food> foods = null;
        try {
            foods = foodDao.getFoodsByBusiness(businessId);
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            ConnUtils.close();
        }
        return foods;
    }

    @Override
    public Food getFoodById(Integer id){
        Food food = null;
        try {
            food = foodDao.getFoodById(id);
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            ConnUtils.close();
        }
        return food;
    }

    @Override
    public List<Food> searchFoodsByName(String foodName) {
        List<Food> foods = null;
        try {
            foods = foodDao.searchFoodsByName(foodName);
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            ConnUtils.close();
        }
        return foods;
    }
}
